<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
  		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<?=$this->include('public/style') ?>
		<?=$this->include('public/script') ?>
	</head>
	<body>
		<div class="layui-tab page-content-wrap">
		  <ul class="layui-tab-title">
		    <li class="layui-this">修改资料</li>
		    <li>修改密码</li>
		  </ul>
		  <div class="layui-tab-content">
		    <div class="layui-tab-item layui-show">
		    	<form class="layui-form"  style="width: 90%;padding-top: 20px;">
                  <input type="hidden" name="<?php echo csrf_token();?>" value="<?php echo csrf_hash();?>">
				  <div class="layui-form-item">
				    <label class="layui-form-label">ID：</label>
				    <div class="layui-input-block">
				      <input type="text" name="id" disabled autocomplete="off" class="layui-input layui-disabled" value="<?=$data["id"]?>">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">用户名：</label>
				    <div class="layui-input-block">
				      <input type="text" name="username" disabled autocomplete="off" class="layui-input layui-disabled" value="<?=$data["username"]?>">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">邮箱：</label>
				    <div class="layui-input-block">
				      <input type="text" name="email" required  lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input" value="<?=$data["email"]?>">
				    </div>
				  </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input" value="<?=$data["name"]?>">
                        </div>
                    </div>
<!--				  <div class="layui-form-item layui-form-text">-->
<!--				    <label class="layui-form-label">备注：</label>-->
<!--				    <div class="layui-input-block">-->
<!--				      <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>-->
<!--				    </div>-->
<!--				  </div>-->
				  <div class="layui-form-item">
				    <div class="layui-input-block">
				      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="adminInfo">立即提交</button>
				    </div>
				  </div>
				</form>
		    </div>
		    <div class="layui-tab-item">
		    	<form class="layui-form"  style="width: 90%;padding-top: 20px;">
                  <input type="hidden" name="<?php echo csrf_token();?>" value="<?php echo csrf_hash();?>">
				  <div class="layui-form-item">
				    <label class="layui-form-label">用户名：</label>
				    <div class="layui-input-block">
				      <input type="text" name="username" disabled autocomplete="off" class="layui-input layui-disabled"  value="<?=$data["username"]?>">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">旧密码：</label>
				    <div class="layui-input-block">
				      <input type="password" name="old_password" required lay-verify="required" placeholder="请输入旧密码" autocomplete="new-password" class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">新密码：</label>
				    <div class="layui-input-block">
				      <input type="password" name="new_password" required lay-verify="required" placeholder="请输入新密码" autocomplete="new-password" class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <label class="layui-form-label">重复密码：</label>
				    <div class="layui-input-block">
				      <input type="password" name="confirm_password" required lay-verify="required" placeholder="请输入确认密码" autocomplete="new-password" class="layui-input">
				    </div>
				  </div>
				  <div class="layui-form-item">
				    <div class="layui-input-block">
				      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="adminPassword">立即提交</button>
				    </div>
				  </div>
				</form>
		    </div>
		  </div>
		</div>
	<script>
		//Demo
		layui.use(['form','element'], function(){
		  var form = layui.form();
		  var element = layui.element();
		  form.render();
		  //监听信息提交
		  form.on('submit(adminInfo)', function(data){
		      let {name,email} = data.field;
		      if(!name || name.length<2){
		          layer.msg("姓名的长度不少于2个字符")
		          return false;
              }
              if(!email || email.length<9){
                  layer.msg("邮箱的长度不少于9个字符")
                  return false;
              }

              layer.confirm('请确认是否提交?', {icon: 3, title:'提示'}, function(index){
                  console.log("222",data.field);
                  // 提交表单
                  $.ajax({
                      url:"/user/doUpdateInfo",
                      method:'post',
                      data:data.field,
                      success:function(res){
                          res = JSON.parse(res)
                          layer.msg(res.msg);
                      }
                  })

                  layer.close(index);
              });
		      return false;
		  });
		  //监听密码提交
		   form.on('submit(adminPassword)', function(data){
               let {old_password,new_password,confirm_password} = data.field;
               if(!old_password || old_password.length<6){
                   layer.msg("旧密码的长度不少于6个字符")
                   return false;
               }
               if(!new_password || new_password.length<6){
                   layer.msg("新密码的长度不少于6个字符")
                   return false;
               }
               if(!confirm_password || confirm_password.length<6){
                   layer.msg("确认密码的长度不少于6个字符")
                   return false;
               }
               if(new_password != confirm_password ){
                   layer.msg("两次输入的密码不一致")
                   return false;
               }
               layer.confirm('请确认是否提交?', {icon: 3, title:'提示'}, function(index){
                   // 提交表单
                   $.ajax({
                       url:"/user/doUpdatePwd",
                       method:'post',
                       data:data.field,
                       success:function(res){
                           res = JSON.parse(res)
                           layer.msg(res.msg);

                           form.render(); //更新全部
                       }
                   })

                   layer.close(index);
               });
		    return false;
		  });
		});
	</script>
	</body>
</html>